package cz.cvut.liy.data;

import java.util.ArrayList;
import java.util.List;

public class Statistic {
	
	private List<Test> tests;
	
	
	public Statistic(){
		this.tests = new ArrayList<Test>();
	}
	
	public void addTest(Test test){
		this.tests.add(test);
	}
	
	public int getTotalCountOfAnswers(){
		int i;
		int count = 0;
		for (i = 0; i < this.tests.size(); ++i){
			count += this.getTotalCountOfTestAnswers(this.tests.get(i));
		}
		return count;
	}
	
	public int getTotalCountOfGoodAnswers(){
		int i;
		int count = 0;
		for (i = 0; i < this.tests.size(); ++i){
			count += this.getTotalCountOfGoodTestAnswers(this.tests.get(i));
		}
		return count;
	}
	
	public int getTotalPercentage(){
		return ((100 * this.getTotalCountOfGoodAnswers()) / this.getTotalCountOfAnswers());
	}
	
	public int getTotalCountOfTestAnswers(Test test){
		int count = 0;
		int i;
		List<Question> questions = test.getQuestions();
		for (i = 0; i < questions.size(); ++i){
			count += questions.get(i).getAnswerCount();
		}
		return count;
	}
	
	public int getTotalCountOfGoodTestAnswers(Test test){
		int count = 0;
		int i;
		List<Question> questions = test.getQuestions();
		for (i = 0; i < questions.size(); ++i){
			count += questions.get(i).getGoodAnswerCount();
		}
		return count;
	}
	
	public int getPercentageOfTest(Test test){
		if(this.getTotalCountOfTestAnswers(test) == 0) return 0;
		return ((100 * this.getTotalCountOfGoodTestAnswers(test)) / this.getTotalCountOfTestAnswers(test));
	}
	
}
